package priv.mill.logdemo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import org.apache.log4j.Logger;

public class PictureTest {

	private static final Logger logger = Logger.getLogger(PictureTest.class);
	
	public static void main(String[] args) {
		
		String path = "F:/ͼƬ/xuenv6.jpg";
		File file = new File(path);
		
//		ServerSocket ss = null;
		InputStream in = null;
		OutputStream fos = null;
		
		try {
			ServerSocket ss = new ServerSocket(9000);
			Socket accept = ss.accept();
			InputStream is = accept.getInputStream();
			
			in = new FileInputStream(file);
			
			int i = in.available();	
			byte[] b = new byte[i];
						
			accept.shutdownInput();
			
			OutputStream os = accept.getOutputStream();
			fos = new FileOutputStream(file);
			fos.write("HTTP/1.1 200 OK\r\n\r\n".getBytes());	
			fos.write(b);
			
			System.out.println("over");
			
			accept.shutdownOutput();
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
//			try {
//				ss.close();
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				fos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}


